import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { Tag, Table } from "antd";
import "./_style.less";
import { sortValidtorData, formulaResult } from "./utils";
import { formatPrice } from "../../tools/Tools";
const noneFormatText = "【无效公式】";
//渲染table
export function renderTable(verifyResult, selectedItems) {
    let dataSource = [];
    const vefiryKeys = Object.keys(verifyResult).sort();
    //组装table数据
    vefiryKeys.map((key, index) => {
        const groupVerifyResult = sortValidtorData(verifyResult[key]);
        if ((selectedItems.length > 0 && selectedItems.includes(key)) ||
            !selectedItems.length ||
            selectedItems.length === 0) {
            dataSource.push(...groupVerifyResult);
        }
    });
    //number排序
    dataSource = dataSource.sort((a, b) => {
        const [numA, subA] = a.checkId
            ? a.checkId.toString().split("-")
            : a.checkId;
        const [numB, subB] = b.checkId
            ? b.checkId.toString().split("-")
            : b.checkId;
        if (Number(numA) < Number(numB))
            return -1;
        if (Number(numA) > Number(numB))
            return 1;
        if (!subA && subB)
            return -1;
        if (subA && !subB)
            return 1;
        if (subA && subB) {
            return Number(subA) - Number(subB);
        }
        return 0;
    });
    const columns = [
        {
            title: "序号",
            dataIndex: "checkId",
            key: "checkId",
            width: 60,
        },
        {
            title: "校验类型",
            dataIndex: "checkType",
            key: "checkType",
            width: 120,
        },
        {
            title: "校验级别",
            dataIndex: "isForce",
            key: "isForce",
            width: 80,
            render: (text, record, index) => {
                return text ? (_jsx("div", { style: {
                        width: 55,
                        height: 22,
                        backgroundColor: "#f50",
                        display: "inline-block",
                        textAlign: "center",
                        color: "white",
                        marginRight: 5,
                    }, children: "\u5F3A\u5236" })) : (_jsx("div", { style: {
                        width: 55,
                        height: 22,
                        backgroundColor: "#87d068",
                        display: "inline-block",
                        textAlign: "center",
                        color: "white",
                        marginRight: 5,
                    }, children: "\u975E\u5F3A\u5236" }));
            },
        },
        {
            title: "被校验项(本表)",
            dataIndex: "beVerifyFormat",
            key: "beVerifyFormat",
            width: 220,
            render: (text, record) => {
                const { beVerifiedFormula, beVerifyIsNA } = record;
                return (_jsx("div", { dangerouslySetInnerHTML: {
                        __html: text ? text : beVerifiedFormula,
                    } }));
            },
        },
        {
            title: "校验项",
            dataIndex: "verifyFormat",
            key: "verifyFormat",
            width: 220,
            render: (text, record) => {
                const { verifyFormula, verifyIsNA } = record;
                return (_jsx("div", { dangerouslySetInnerHTML: {
                        __html: text ? text : verifyFormula,
                    } }));
            },
        },
        {
            title: "差异",
            dataIndex: "name",
            key: "name",
            width: 190,
            render: (text, record, index) => {
                const { beVerifiedFormulaResult, verifyFormulaResult, beVerifyIsNA, verifyIsNA, } = record;
                return (_jsxs(_Fragment, { children: [_jsxs("div", { children: ["\u5DE6\u8FB9\uFF1A", beVerifyIsNA
                                    ? `${formatPrice(beVerifiedFormulaResult)}(N/A)`
                                    : formatPrice(beVerifiedFormulaResult)] }), _jsxs("div", { children: ["\u53F3\u8FB9\uFF1A", verifyIsNA
                                    ? `${formatPrice(verifyFormulaResult)}(N/A)`
                                    : formatPrice(verifyFormulaResult)] }), _jsxs("div", { children: ["\u5DEE\u989D\uFF1A", formulaResult(record)] })] }));
            },
        },
        {
            title: "校验结果",
            dataIndex: "fullFormulaResult",
            key: "fullFormulaResult",
            width: 100,
            render: (text, record) => {
                return (_jsx(Tag, { color: !text ? "#FD4037" : "#01B226", children: !text ? "不通过" : "通过" }));
            },
        },
    ];
    return _jsx(Table, { columns: columns, dataSource: dataSource, pagination: false });
}
